<?php
declare (strict_types = 1);

namespace app\adminapi\controller;

use adminmatrix\admin\BaseController;
use adminmatrix\admin\service\JsonService;
use app\adminapi\logic\admin\AdminLogic;
use app\common\annotate\permission;
use app\Request;
use hg\apidoc\annotation as Apidoc;
use think\response\Json;

#[
    Apidoc\Title("管理员账号管理"),
    Apidoc\Group("account"),
]
class AccountController extends BaseController
{
    #[
        Apidoc\Title("登录"),
        Apidoc\Method("POST"),
        Apidoc\Param(name: "username", type: "string", require: true, default: NULL, desc: "用户名"),
        Apidoc\Param(name: "password", type: "string", require: true, desc: "密码"),
        Apidoc\Param(name: "remember", type: "boolean", default: false, desc: "是否记住密码"),
        permission
    ]
    public function login(Request $request , AdminLogic $logic): Json
    {    
        $admin = $logic->login($request);

        return JsonService::success("登录成功" , $admin);
    }


    #[
        Apidoc\Title("退出登录"),
        permission
    ]
    public function Logout(Request $request , AdminLogic $logic) : Json
    {
        try {
            $logic->logout($request);
            return  JsonService::success("退出登录成功");
        } catch (\Exception $exception)
        {
            return  JsonService::fail($exception->getMessage());
        }
    }
}
